import { request } from '@/request/hook'
import { Md5 } from 'ts-md5';
/**
 *put和post一样都可传params和data  params就是query, data就是body
*/
export let http = {
  getIndexInfo: <T>() => {
    return request({
      url: '/index-infos',
      method: 'get',
    })
  },

  //用户登录
  login: <T>(name: string, psw: string) => request({
    url: 'user/login',
    method: 'post',
    data: {
      loginName: name,
      passwordMd5: Md5.hashStr(psw)
    }
  }),
  //注册用户
  register: <T>(name: string, psw: string) => request({
    url: 'user/register',
    method: 'post',
    loginName: name,
    password: psw
  }),
  //添加到购物车 deleteCartList, changeGoodsNumber
  addCarts: <T>(goodsId:number,goodsCount:number) => request({
    url: '/shop-cart',
    method: 'post',
   data:{
    goodsId,
    goodsCount
   }
  }),
  getCartList: <T>() => {
    return request({
      url: '/shop-cart',
      method: 'get',
    })
  },
//删除购物车商品
  deleteCartList: <T>(param: T) => request({
    url: `/shop-cart/${param}`,
    method: 'delete'
  }),

//改变购物车商品数量
  changeGoodsNumber: <T>(param: T) =>{ 
     return request({
    url: '/shop-cart',
    method: 'put',
    data:param
  })},

  
  getInfoData: <T>(id:number) => {
    return request({
      url: '/goods/detail/' + id,
      method: 'get',
    })
  },

  putUserInfo: <T>(param: T) => request({
    url: '/test/put',
    method: 'put',
    params: param,
    data: param
  }),

  postUserInfo: <T>(param: T) => request({
    url: '/test/post',
    method: 'post',
    params: param,
    data: param
  }),

  deleteUserInfo: <T>(param: T) => request({
    url: '/test/delete',
    method: 'delete',
    params: param,
    data: param
  })
}
